package com.loyal.loyalerp.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class Canlendar {
    public static void main(String[] args) throws ParseException {
		Canlendar canlendar = new Canlendar();
		canlendar.importDate();
	}
    //导入一年信息
    public void importDate() throws ParseException {
    	String years = "2018";
    	SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    	SimpleDateFormat format1 = new SimpleDateFormat("yyyy年MM月dd日EE",Locale.CHINA);
    	Date start = format.parse(years+"0101");//开始时间
    	Date end = format.parse(years+"1231");//结束时间
    	List<Date> li = splitDate(start, end);
    	for(Date date:li) {
    		String newDate = format1.format(date);
    		String yearNum = newDate.substring(0, newDate.indexOf("年"));
    		String month = newDate.substring(newDate.indexOf("年")+1,newDate.indexOf("月"));
    		String weekNum = newDate.substring(newDate.indexOf("日")+1,newDate.length());
    		System.out.println("年份:"+yearNum+",月份:"+month+"weekNum:"+weekNum);
    	}
    }
    
    //日期分隔
    public List<Date> splitDate(Date start,Date end){
    	Long spi = end.getTime() - start.getTime();
    	//计算相隔的天数
    	Long num = spi/(1000*60*60*24);
    	List<Date> list = new ArrayList<Date>();
    	list.add(start);
    	for(int i=1;i<=num;i++) {
    		list.add(new Date(list.get(i-1).getTime()+(1000*60*60*24)));
    	}
    	return list;
    }
}
